package com.wendy.common.core.constant;

import com.fasterxml.jackson.annotation.JsonCreator;

import java.util.Arrays;
import java.util.Optional;

/**
 * 枚举的基础类
 * @Author: ALEX WANG
 * @Date: 2020/3/16 11:11
 */
public interface BaseEnum<T  extends  BaseEnum ,C> {

    public  String getName();
    public   C getCode();
    @JsonCreator
    public static <T extends  BaseEnum,C> T  getEnumByCode(Class<T> enumClass, C code){
        T[] enums = enumClass.getEnumConstants();
        Optional<T> optional = Arrays.asList(enums).stream().filter(baseEnum -> baseEnum.getCode().equals(code)).findAny();
        if (optional.isPresent()){
            return optional.get();
        }
        return null;
    }






}
